# 按照面向对象思想定义页面对象【po】
import time
from selenium.webdriver.chrome import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from base.page_base import BasePage
from tools import DriverTools


class RegisterPage(BasePage):
    # 静态数据：属性
    def __init__(self, driver):
        # 浏览器对象
        super().__init__(driver)
        # 手机号元素信息
        self.phone = By.XPATH, '//*[@id="phone"]'
        # 密码元素信息
        self.password = By.XPATH, '//*[@id="password"]'
        # 验证码元素信息
        self.code = By.XPATH, '//*[@id="verifycode"]'
        # 短信验证码按钮元素信息
        self.get_phone_code = By.XPATH, '//*[@id="get_phone_code"]'
        # 手机验证码元素信息
        self.phone_code = By.XPATH, '//*[@id="phone_code"]'
        # 注册按钮元素信息
        self.register_button = By.XPATH, '//*[@id="reg_form"]/div[2]/div[6]/input'
        #获取注册成功结果
        self.result = By.XPATH, '//*[@id="step3"]/div/div/h1'
        # 获取注册失败结果
        self.fail_result = By.XPATH, '//*[@id="reg_form"]/div[1]'

    def register(self,phone,pwd,code='8888',phone_code='666666'):
        # 输入手机号
        self.fd_element(self.phone).send_keys(phone)
        # 输入密码
        self.fd_element(self.password).send_keys(pwd)
        # 输入验证码
        self.fd_element(self.code).send_keys(code)
        # 获取手机验证码
        self.fd_element(self.get_phone_code).click()
        time.sleep(2)
        # 输入手机验证码
        self.fd_element(self.phone_code).send_keys(phone_code)
        # 点击注册按钮
        self.fd_element(self.register_button).click()


    def get_success_result(self):
        # 获取注册结果\
        time.sleep(2)
        result = self.fd_element(self.result).text
        return result


    def get_fail_result(self):
        # 获取注册结果\
        result = self.fd_element(self.fail_result).text
        return result